<?php
namespace cosocket\system\server;

use cosocket\system\server\websocket\AsyncWebSocket;
use cosocket\system\server\websocket\CoWebSocket;

class ServerFactory
{
    public static function create($config = [])
    {
        $type = $config['server_type'] ?? 'coroutine';
        $host = $config['host'] ?? '0.0.0.0';
        $port = $config['port'] ?? 5678;

        switch ($type) {
            case 'async':
                return new AsyncWebSocket($host, $port, $config['async'] ?? []);
            case 'coroutine':
            default:
                return new CoWebSocket($host, $port, $config['coroutine'] ?? []);
        }
    }
}